﻿using System;
using System.Collections.Generic;
using System.Xml;

/// <summary>
/// StatusType provides an enumeration of values that detail the status of queries or requests.
/// </summary>
public enum StatusType
{
    /// <summary>Query or request successful.</summary>
    Success,
    /// <summary>Query or request successful, but with warnings.</summary>
    Warning,
    /// <summary>Query or request not successful.</summary>
    Failure
}


/// <summary>
///StatusMessage returned by service methods 
/// </summary>
public class StatusMessage
{
    private XmlDocument xDoc;

    public XmlElement Element
    {
        get { return xDoc.DocumentElement; }
    }

    private StatusType _status;
    public StatusType Status
    {
        get { return _status; }
    }

    public StatusMessage(StatusType status, string message)
    {
        _status = status;
        xDoc = new XmlDocument();
        XmlDeclaration dec = xDoc.CreateXmlDeclaration("1.0", null, null);
        xDoc.AppendChild(dec);
        // Create the root element
        XmlElement root = xDoc.CreateElement("SDMX_SAE_TOOL");
        xDoc.AppendChild(root);

        XmlElement s = xDoc.CreateElement("StatusMessage");
        s.SetAttribute("status", status.ToString());
        if (string.IsNullOrEmpty(message) == false)
        {
            XmlElement m = xDoc.CreateElement("MessageText");
            m.InnerText = message;
            s.AppendChild(m);
        }
        root.AppendChild(s);
    }
}
